package com.demoworld.aspect;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.ObjectMapper;

import java.io.IOException;

/**
 * Created by francis on 2018/1/21.
 */
public class JsonUtil {
    private static final ObjectMapper objectMapper = new ObjectMapper();

    public JsonUtil() {
    }

    public static <T> T fromJson(String value, TypeReference<T> type) {
        T result = null;

        try {
            result = objectMapper.readValue(value, type);
            return result;
        } catch (IOException var4) {
            throw new RuntimeException(var4);
        }
    }

    public static <T> T fromJson(String value, Class<T> type) {
        T result = null;

        try {
            result = objectMapper.readValue(value, type);
            return result;
        } catch (IOException var4) {
            throw new RuntimeException(var4);
        }
    }

    public static <T> String toJson(T value) {
        try {
            return objectMapper.writeValueAsString(value);
        } catch (JsonProcessingException var2) {
            throw new RuntimeException(var2);
        }
    }
}
